<?php
/**
 * Created by PhpStorm.
 * User: qixiuxiu
 * Date: 2017/4/5
 * Time: 15:47
 */
use Symfony\Component\Routing;
use Symfony\Component\HttpFoundation\Response;

//判断给定年份是否是闰年
function is_leap_year($year = null){
    if (null == $year){
        $year = date('Y');
    }
    return 0 === $year % 400|| (0 === $year % 4 && 0 !== $year % 100 );
}
//Routing组件依赖一个RoutingCollection实例
$routes = new Routing\RouteCollection();
/*路由集合中的每一个入口（entry），都是通过一个名字（name。如hello）和一个Route实例来定义，
该实例则通过一个route pattern（路由匹配）和一个路由属性（route attributes）的“默认值”数组来定义（array('name' => 'World'）。*/
$routes->add('index',new Routing\Route('/index/{name}',array('name'=>'world')));
$routes->add('bye',new Routing\Route('bye'));
//作为一个约定，对于每个路由来说，其关联的控制器被配置在_controller这个路由属性中（route attribute）
//$routes->add('leap_year',new Routing\Route('/is_leap_year/{year}',array(
//    'year' => null,
//    '_controller' => function($request){
//    if (is_leap_year($request->attributes->get('year'))){
//        return new Response('yep,this is a leap year');
//    }
//        return new Response('nope,this is not a leap year');
//}
//)));
$routes->add('leap_year', new Routing\Route('/is_leap_year/{year}', array(
    'year' => null,
    '_controller' =>  array(new LeapYearController(), 'indexAction'),
)));

return $routes;